extends CharacterBody2D

class_name Enemy
@onready var find_turn_area: Area2D = $FindTurnArea
@onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D
@onready var animation_player: AnimationPlayer = $AnimationPlayer

@export var SPEED: int = 60
var gravity: int = 1000
@export var direction: int = 1	# 默认为 1 向右移动
func _ready() -> void:
	animated_sprite_2d.flip_h = true
	find_turn_area.area_entered.connect(on_area_entered)



func _physics_process(delta: float) -> void:
	velocity.x = direction * SPEED
	velocity.y += gravity * delta
	animated_sprite_2d.flip_h = true if direction == 1 else false
	move_and_slide()

func on_area_entered(area_2d):
	direction *= -1
	
func die():
	animation_player.play("die")
